package com.goparry.taskman.maps;

import java.util.ArrayList;
import java.util.List;

import com.google.android.maps.GeoPoint;

public class GeoList {
	private List<GeoLocation> mGeoLocations = new ArrayList<GeoLocation>();

	public GeoList() {
	}
	public List<GeoLocation> getGeoLocations() {
		return mGeoLocations;
	}
	public void add(GeoLocation location) {
		mGeoLocations.add(location);
	}
	public GeoLocation get(int index) {
		return mGeoLocations.get(index);
	}
	public GeoPoint getCenter() {
		// TODO generate a better center based on the span.
		int lat, lon;
		int sumLat=0, sumLon=0;
		
		for (GeoLocation gl : mGeoLocations) {
			sumLat += gl.getLatitudeE6();
			sumLon += gl.getLongitudeE6();
		}
		
		lat = sumLat / mGeoLocations.size();
		lon = sumLon / mGeoLocations.size();
		
		return new GeoPoint(lat, lon);
	}
	public int getLatSpan() {
		int latMin =  80000000;
		int latMax = -80000000;
		for (GeoLocation gl : mGeoLocations) {
			if (gl.getLatitudeE6() < latMin) latMin = gl.getLatitudeE6();
			if (gl.getLatitudeE6() > latMax) latMax = gl.getLatitudeE6();
		}
		
		return latMax-latMin;
	}
	public int getLonSpan() {
		int lonMin =  180000000;
		int lonMax = -180000000;
		for (GeoLocation gl : mGeoLocations) {
			if (gl.getLongitudeE6() < lonMin) lonMin = gl.getLongitudeE6();
			if (gl.getLongitudeE6() > lonMax) lonMax = gl.getLongitudeE6();
		}
		
		return 2*(lonMax-lonMin);
	}

}
